﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Studio77.GuessTheWordsForWP7.Views
{
    public partial class VisualKeyBoard : UserControl
    {
        static List<string> keys;
        const int columns = 8;
        const int rows = 3;

        public VisualKeyBoard()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(VisualKeyBoard_Loaded);
        }

        VisualKeyBoardLamp lamp;

        public void RefreshLampCount()
        {
            lamp.UpdateUI();
        }

        void VisualKeyBoard_Loaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= new RoutedEventHandler(VisualKeyBoard_Loaded);
            this.cvsRoot.Children.Clear();
            if (keys == null)
            {
                keys = new List<string>();
                keys.Add("A");
                keys.Add("B");
                keys.Add("C");
                keys.Add("D");
                keys.Add("E");
                keys.Add("F");
                keys.Add("G");
                keys.Add("H");
                keys.Add("J");
                keys.Add("K");
                keys.Add("L");
                keys.Add("M");
                keys.Add("N");
                keys.Add("O");
                keys.Add("P");
                keys.Add("Q");
                keys.Add("R");
                keys.Add("S");
                keys.Add("T");
                keys.Add("W");
                keys.Add("X");
                keys.Add("Y");
                keys.Add("Z");
            }
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {

                    int index = i * columns + j;
                    double left = 60 * j;
                    double top = i * 50;

                    String keyStr = "";
                    if (index < keys.Count)
                    {
                        keyStr = keys[index];
                        VisualKeyBoardItem item = new VisualKeyBoardItem();
                        Canvas.SetLeft(item, left);
                        Canvas.SetTop(item, top);
                        item.SetContent(keyStr);
                        this.cvsRoot.Children.Add(item);
                    }
                    else
                    {
                        lamp = new VisualKeyBoardLamp();
                        Canvas.SetLeft(lamp, left);
                        Canvas.SetTop(lamp, top);
                        this.cvsRoot.Children.Add(lamp);
                        lamp.UpdateUI();
                    }
                }
            }
        }
    }
}
